<?php
/**
 * 设置免考和移除员工
 */
apf_require_controller("Abstract");
apf_require_class("Bll_Jx_Relation");
apf_require_class("Bll_Jx_Plan");
apf_require_class("Bll_Hr_Property");
class Setting_ChangeToAvoidController extends AbstractController {

    public function handle_request() {
        $params = $this->request->get_parameters();
        $this->rel_bll = new Bll_Jx_Relation();
        $params['type'] = (empty($params['type']) || $params['type']==1)  ? 1 : 2;

        $date = 20130103;

        $dep_list = $this->rel_bll->get_department_list();
        if($this->request->is_post_method()){
            if($params['type'] ==1){
                if(!empty($params['code'])){
                    $this->rel_bll->set_no_kp($params['code']);
                }
            }else{
                $uids = $params['leaveUsers'];
                $this->rel_bll->remove_user_kp($uids);
            }
        }
        $city_bll = new Bll_Hr_Property();
        $city_list = $city_bll->get_sort_city_list();

        if($params['type'] ==1){//免考
            $datalist = $this->rel_bll->get_kp_user();
        }else{//离职
            $datalist = $this->get_dimission_users($date);
        }
        //print_r($datalist);
        $this->request->set_attribute('bu_list', array(1=>'爱房',2=>'安居客',3=>'好租',4=>'金铺'));
        $this->request->set_attribute('city_list', $city_list);
        $this->request->set_attribute('dep_list', $dep_list);
        $this->request->set_attribute('datalist', $datalist);
        $this->request->set_attribute('params', $params);
        return 'Setting_ChangeToAvoid';
    }
    /**
     * 查询主管没有打分的离职员工
     * @param int $date
     * @return multitype:
     */
    private function get_dimission_users($date){
        $datalist = $this->rel_bll->get_dimission_user();

        if(!empty($datalist)){
            $uids = array_keys($datalist);

            $_where = array(
                    "userId IN(".implode(',',$uids).") AND 1=?"=>1,
                    "serachMonth"=>$date,
                    'treasurerScore'=>0
            );

            $plan_bll = new Bll_Jx_Plan();
            $data = $plan_bll->find_performance($_where);
            if(!empty($data)){
                foreach ($data as $val){
                    unset($datalist[$val['userId']]);
                }
            }
        }
        return $datalist;
    }
}